#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e6+1;
ll n,a[N],c,cc[3];
int color[N];
int T;
int main()
{
    ios::sync_with_stdio(false);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    for(int i=1;i<=T;i++){
        c=0;
        cin>>n;
        for(ll j=1;j<=n;j++){
            cin>>a[j];
            for(ll x=j-1;x;x--){
                if(a[x]==a[j]){
                    c+=a[j];
                    continue;
                }
            }

        }
        cout<<c<<endl;
    }
    return 0;
}
